package com.kye.express.business.jd.goods_detail.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.kye.model.bean.jd.address.JDAddressBean;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 31/01/2018
 * @updated : 31/01/2018
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public class JDAddressModel implements Parcelable {

    private JDAddressBean addressBean;
    private boolean isSelected;

    public JDAddressModel(JDAddressBean addressBean, boolean isSelected) {
        this.addressBean = addressBean;
        this.isSelected = isSelected;
    }

    public JDAddressBean getAddressBean() {
        return addressBean;
    }

    public void setAddressBean(JDAddressBean addressBean) {
        this.addressBean = addressBean;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.addressBean, flags);
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    public JDAddressModel() {
    }

    protected JDAddressModel(Parcel in) {
        this.addressBean = in.readParcelable(JDAddressBean.class.getClassLoader());
        this.isSelected = in.readByte() != 0;
    }

    public static final Parcelable.Creator<JDAddressModel> CREATOR = new Parcelable.Creator<JDAddressModel>() {
        @Override
        public JDAddressModel createFromParcel(Parcel source) {
            return new JDAddressModel(source);
        }

        @Override
        public JDAddressModel[] newArray(int size) {
            return new JDAddressModel[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof JDAddressModel)) return false;

        JDAddressModel that = (JDAddressModel) o;

        return addressBean.equals(that.addressBean);
    }

    @Override
    public int hashCode() {
        return addressBean.hashCode();
    }
}
